package visitorpattern;

import java.util.LinkedList;

import bookworm.Book;
import bookworm.CreateBooksBasedOnReviews;
import bookworm.Review;

import graph.BookReviewNode;

public class BooksFromSpecificTagVisitor implements Visitor
{
	private LinkedList<Review> reviewsFromTag;
	private String specificTag;
	
	public BooksFromSpecificTagVisitor(String specificTag)
	{
		reviewsFromTag = new LinkedList<Review>();
		this.specificTag = specificTag;
	}
	
	@Override
	public void visitBookReviewNode(BookReviewNode nodeVisited) 
	{
		Review reviewFromNode = nodeVisited.getReviewData();
		LinkedList<String> tagsFromReview = reviewFromNode.getTags();
		for(int i = 0; i < tagsFromReview.size(); i++)
		{
			String oneTag = tagsFromReview.get(i);
			if(oneTag.compareTo(this.specificTag) == 0)
			{
				this.reviewsFromTag.add(reviewFromNode);
			}
		}
	}
	
	public LinkedList<Book> getBooksFromTag() 
	{
		LinkedList<Book> booksFromTag = CreateBooksBasedOnReviews.createBooksFromReviews(reviewsFromTag);
		return booksFromTag;
	}

}
